//package com.dmgis.hndz.controller;
//
//import cn.hutool.core.lang.Snowflake;
//import cn.hutool.core.util.IdUtil;
//import cn.hutool.http.HttpRequest;
//import com.alibaba.fastjson.JSONObject;
//import com.mascloud.model.MoModel;
//import com.mascloud.model.StatusReportModel;
//import com.mascloud.sdkclient.Client;
//import org.bson.types.ObjectId;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.mongodb.core.MongoTemplate;
//import org.bson.Document;
//import org.bson.types.Binary;
//import org.springframework.data.mongodb.core.query.Criteria;
//import org.springframework.data.mongodb.core.query.Query;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.servlet.http.HttpServletRequest;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.util.Base64;
//import java.util.List;
//
///**
// * @author: xwx
// * @description: 测试mongodb数据下载
// * @date: 2024/9/21
// * @version: 1.0
// */
//@RestController
//@RequestMapping("test")
//public class TestController {
//    @Autowired
//    private MongoTemplate template;
//    private static final String snowflakeStr = "1839583293645918208";
//
//    @RequestMapping("test")
//    public String test(@RequestBody JSONObject object) {
//        System.out.println(object);
//        getFileWithBase641();
//        return "test";
//    }
//    @RequestMapping(value = "/test1",method = RequestMethod.POST, produces = "application/json")
//    public String test1(@RequestBody JSONObject jsonObject) {
//        String msg = jsonObject.getString("msg");
//        String phone = jsonObject.getString("phone");
//        String[] phones = phone.split(",");
//        Client client = Client.getInstance();
//        boolean login = client.login("http://112.35.4.197:15000", "smsTest1", "GDHZxwx@#123", "山东省国土空间生态修复中心");
//        if (login){
//            //Snowflake snowflake = IdUtil.createSnowflake(1, 1);
//            //String snowflakeStr = snowflake.nextIdStr();
//            //String[] strings = {"15973835748"};
//            System.out.println(msg);
//            int i = client.sendDSMS(phones, msg, "", 5, "jzrqX54tG", snowflakeStr, true);
//            switch (i){
//                case 1:
//                    System.out.println("发送成功");
//                    break;
//                case 2:
//                    System.out.println("发送失败，原因：短信内容不符合要求");
//                    break;
//                default:
//                    System.out.println("发送失败");
//            }
//            List<StatusReportModel> report = client.getReport();
//            System.out.println(report);
//            List<MoModel> mo = client.getMO();
//            System.out.println(mo);
//            return "登录成功";
//        }
//        return "短信发送失败";
//    }
//
//    public void getFileWithBase641() {
//        Criteria criteria = Criteria
//                .where("data").exists(true)
//                .and("_id").is("66a315580cd6546798cf1a8e")
//                .and("datetime").is("2024-07-16 00:00:00");
//        List<Document> result = template.find(new Query(criteria), Document.class, "sk_grid_file");
//        Document document = result.get(0);
//        Binary binaryData = (Binary) document.get("data");
//        byte[] dataBytes = binaryData.getData();
//
//        // 将字节数组转换为 Base64 编码的字符串
//        String base64Content = Base64.getEncoder().encodeToString(dataBytes);
//        // 获取 _id 字段并转换为字符串
//        ObjectId objectId = (ObjectId) document.get("_id");
//        String fileName = objectId.toString().toUpperCase();
//        // 解码 Base64 字符串并保存到文件
//        byte[] decode = Base64.getDecoder().decode(base64Content);
//        String newFilePath = "D:\\game\\" + fileName + ".grid";
//        try (FileOutputStream fos = new FileOutputStream(newFilePath)) {
//            fos.write(decode);
//            System.out.println("文件已成功保存，路径：" + newFilePath);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//}
